<{if $addrlist}>
  <ul class="receiver-sel">
  <{foreach from=$addrlist key=iloop item=addr}>
   <li>
	<label><input type="radio" name="delivery[addr_id]" value="<{$addr.addr_id}>" class="receiver_radio_addr_id" <{if $addr.def_addr}> checked<{/if}>><{$addr.addr_region|region}> <{$addr.addr_label}><{if $addr.def_addr}><input type="hidden" name="def_addr" value="<{$addr.addr_id}>" /><{/if}>
	</label>  
	</li>
	<{/foreach}>
	<li>
		<label><input type="radio" name="delivery[addr_id]" value="0" class="receiver_radio_addr_id other_addr"><{t}>其他收货地址<{/t}></label>
	</li>
	
  </ul>
  <div id="checkout-recaddr"></div>
<{else}>
<div id='checkout-recaddr'>
   <{include file="site/common/rec_addr.html"}>
</div>
<{/if}>

<input type="hidden" name="has_def_addr" value="<{if $def_arr_addr_other}>1<{else}>0<{/if}>" />
<input type="hidden" name="has_def_addr_member" value="<{if $def_arr_addr_member}>1<{else}>0<{/if}>" />

<div class='receivermore' style="padding:0 0 0 108px">
<input type='checkbox'<{if $def_arr_addr.day}> checked="checked"<{/if}> onclick='$(this).getNext("div")[this.checked?"show":"hide"]();'/><{t}> 指定送货时间:<{/t}>
<div style='<{if !$def_arr_addr.day}>display:none;<{/if}>margin-top:4px'>
 <{t}>送货时间：<{/t}><select class="inputstyle"  style="margin-left:10px;" name="delivery[day]" onchange="$('specal_day').style.display=(this.value=='specal')?function(){$('specal_day').getFirst().makeCalable(); return '';}():'none'">
		<option<{if !$def_arr_addr.day}> selected="selected"<{elseif $def_arr_addr.day == '任意日期'}> selected="selected"<{/if}> value="<{t}>任意日期<{/t}>"><{t}>任意日期<{/t}></option>
		<option<{if $def_arr_addr.day == '仅工作日'}> selected="selected"<{/if}> value="<{t}>仅工作日<{/t}>"><{t}>仅工作日<{/t}></option>
		<option<{if $def_arr_addr.day == '仅休息日'}> selected="selected"<{/if}> value="<{t}>仅休息日<{/t}>"><{t}>仅休息日<{/t}></option>
		<option<{if $def_arr_addr.day == 'specal'}> selected="selected"<{/if}> value="specal"><{t}>指定日期<{/t}></option>
	  </select>&nbsp;
	  <span id="specal_day"<{if !$def_arr_addr.specal_day}> style="display:none"<{/if}>>
		 <{input type="text" name="delivery[specal_day]" class="cal inputstyle" value=$def_arr_addr.specal_day real=true style="width:80px" readonly=true}>
	  </span>
	  <{if $def_arr_addr.specal_day}>
	  <script>
		(function(){
			$('specal_day').getFirst().makeCalable(); 
			return '';
		})();
	  </script>
	  <{/if}>
	<select class="inputstyle" name="delivery[time]">
		<option<{if $def_arr_addr.time == '任意时间段'}> selected<{/if}> value="<{t}>任意时间段<{/t}>"><{t}>任意时间段<{/t}></option>
		<option<{if $def_arr_addr.time == '上午'}> selected<{/if}> value="<{t}>上午<{/t}>"><{t}>上午<{/t}></option>
		<option<{if $def_arr_addr.time == '下午'}> selected<{/if}> value="<{t}>下午<{/t}>"><{t}>下午<{/t}></option>
		<option<{if $def_arr_addr.time == '晚上'}> selected<{/if}> value="<{t}>晚上<{/t}>"><{t}>晚上<{/t}></option>
	  </select>
  </div>
</div>

<script>
window.addEvent('domready',function(){

	var url_area = '<{link app=b2c ctl="site_cart" act="getAddr" }>';
	
	var deliverying={
		init:function(){
		
			$E('#receiver').addEvent('click',function(e){
				var target=$(e.target);												
				if (target.hasClass('receiver_radio_addr_id'))
				deliverying.generateShippings(target);
			});
			
			var addlistRadios=$ES('input[name^=delivery[addr_id]','receiver');
			var _has_def_addr = $E('input[name^=has_def_addr]').getValue();
			var _has_def_addr_member = $E('input[name^=has_def_addr_member]').getValue();
			
			if(addlistRadios.length){
				var def=$E('input[name^=def_addr]'),
					cur=!def?addlistRadios[0]:$E('.receiver_radio_addr_id[value='+def.value+']'),
					arg=-1;
				if (_has_def_addr_member == '1') arg=def.value;
				else if (_has_def_addr == '1') arg=-1;
				else arg=cur.value;
					
				deliverying.generateShippings(cur,arg);
				$E('#receiver').store('def_recaddr', cur);
			}			
		},		
		generateShippings:function(target, index){
			target.checked = true;             
			var _value=(index != '-1') ? target.value : '-1';
			var _extends_args = $E('#order-create input[name^=json_extend_args]') ? $E('#order-create input[name^=json_extend_args]').value : null;
			
			new Request.HTML({
				url:url_area,
				update:'checkout-recaddr',
				method:'get',
				data:{'addr_id':_value,'member_id':$E('input[name^=purchase[member_id]]')?$E('input[name^=purchase[member_id]]').value:null,'extends_args':_extends_args},
				onRequest:function(){
				  $('checkout-recaddr').set('html','<div class="fontcolorGreen">loading...</div>');
				},
				onFailure:function(){
					alert('<{t}>由于网路延迟问题，请重新刷新页面！<{/t}>');
				},
				onComplete:function(){
				   if(_value=='0')
				   return $('shipping').set('html','<div class="valierror clearfix" style=" padding-left:20px"><{t}>请先完善收货信息.<{/t}></div>');	  
				   
				   
				   if(lastsel=$ES('#checkout-select-area select').getLast()){					  
					  if(!lastsel.getValue()||lastsel.getValue()=='_NULL_'){
						   $('shipping').set('html','<div class="valierror clearfix" style=" padding-left:20px"><{t}>请先完善收货信息.<{/t}></div>');
						   MessageBox.error('<{t}>请重新选择：收货地区.<{/t}>');
					  }
				   }				 
				}}).send();
		}
	};
    deliverying.init();
       
	$('receiver_info').addEvent('click', function(el){
		var addlistRadios=$ES('input[name^=delivery[addr_id]','receiver');
		
		var _has_def_addr = $ES('input[name^=has_def_addr]').getValue();
		if(addlistRadios.length){
			var def=$E('input[name^=def_addr]');					
			var cur=!def?addlistRadios[0]:$E('.receiver_radio_addr_id[value='+def.value+']');
			if (_has_def_addr == '1')
				deliverying.generateShippings(cur, def.value);
		}
	});
});
</script>